package com.example.shop_2302.adapter

import android.widget.ImageView
import android.widget.Toast
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.CategoryEntityItem
import com.example.base.entity.Child
import com.example.shop_2302.R
import com.example.shop_2302.utils.GlideUtils

class TwoAdapter:BaseQuickAdapter<CategoryEntityItem,BaseViewHolder>(R.layout.item_two) {
    override fun convert(holder: BaseViewHolder, item: CategoryEntityItem) {
        holder.setText(R.id.two_tv,"----${item.name}----")
        //给rv赋值
        val rv = holder.getView<RecyclerView>(R.id.two_rv)
        val twoChildAdapter = TwoChildAdapter()
        twoChildAdapter.data.addAll(item.child)
        rv.adapter = twoChildAdapter
        rv.layoutManager = GridLayoutManager(context,3)

    }
}

/**
 * rv_two中的rv的适配器
 */
class TwoChildAdapter:BaseQuickAdapter<Child,BaseViewHolder>(R.layout.item_two_child) {
    override fun convert(holder: BaseViewHolder, item: Child) {
        holder.setText(R.id.child_tv,item.name)
        GlideUtils.loadNormal(context,item.extra,holder.getView(R.id.child_iv))
        holder.itemView.setOnClickListener {
            ARouter.getInstance().build("/app/CateXqActivity").withString("cname",item.name)
                .withInt("cid",item.id)
                .navigation()
        }
       /* holder.getView<ImageView>(R.id.child_iv).setOnClickListener {
            ToastUtils.showLong("点击了图片${item.name}")
        }*/
    }
}

